/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.ical;


import java.io.File;
import java.util.HashMap;
import java.util.Vector;
import us.k5n.k5ncal.data.Repository;
import us.k5n.k5ncal.data.RepositoryChangeListener;

/**
 *
 * @author Administrator
 */
public class ERPRepository extends Repository{
    public static int DAYCOUNT=30;
    private Vector<ERPCalendar> cals;
    protected HashMap<String, Vector> cachedERPEvents;

    public ERPRepository(File dir, Vector<us.k5n.k5ncal.data.Calendar> calendars, boolean strictParsing) {
        super(dir, calendars, strictParsing);
        cals=new Vector();
    }

    @Override
    public Vector getEventInstancesForDate(int year, int month, int day) {
        Vector allDayEvents=super.getEventInstancesForDate(year, month, day);
        if(allDayEvents==null)
            allDayEvents=new Vector();
       for(ERPCalendar cal:cals){
           if(cal.isSelected()){
               Vector erpEvents=cal.getEventInstancesForDate(year,month,day);
               if(erpEvents!=null)
                   allDayEvents.addAll(erpEvents);
           }
       }
        return allDayEvents;
    }


    public void addERPCalendar ( ERPCalendar newCal) {
        this.cals.add(newCal);
        for ( int i = 0; i < this.changeListeners.size (); i++ ) {
	     RepositoryChangeListener l = this.changeListeners.elementAt ( i );
	     l.calendarAdded (newCal);
	}
    }

    public Vector<ERPCalendar> getERPCalendars () {
	   return this.cals;
    }

    void updateCalendar(ERPCalendar c) {
        
    }

    void removeCalendar(ERPCalendar c) {
        cals.remove(c);
        for ( int i = 0; i < this.changeListeners.size (); i++ ) {
	     RepositoryChangeListener l = this.changeListeners.elementAt ( i );
	     l.calendarDeleted(c);
	}
    }
}
